﻿Public Class ucBaseControlPanel
	Public Event ControlsGroupEnabledChanged As EventHandler

	Protected dataSrc As Object
	Protected defDataSrc As Object

	Public Property DefaultDataSourceObject() As Object
		Get
			Return defDataSrc
		End Get
		Set(ByVal value As Object)
			defDataSrc = value
		End Set
	End Property

	Public Property ControlsGroupEnabled() As Boolean
		Get
			Return chkEnablePanel.Checked
		End Get
		Set(ByVal value As Boolean)
			chkEnablePanel.Checked = value
		End Set
	End Property

	Public ReadOnly Property DataSource() As Object
		Get
			Return dataSrc
		End Get
	End Property

	Public Sub New()
		InitializeComponent()

		grpPanel.DataBindings.Add("Enabled", chkEnablePanel, "Checked", False, DataSourceUpdateMode.Never)
		btnPreview.DataBindings.Add("Enabled", grpPanel, "Enabled", False, DataSourceUpdateMode.Never)
	End Sub

	Private Sub grpPanel_EnabledChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles grpPanel.EnabledChanged
		RaiseEvent ControlsGroupEnabledChanged(sender, e)
	End Sub

	Public Overridable Sub SetDataSource(ByVal data As Object)
		dataSrc = Nothing
		notificationBindingSource.DataSource = data
		dataSrc = data
	End Sub

	Public Overridable Sub Clear()
		dataSrc = Nothing
		If DefaultDataSourceObject Is Nothing Then Exit Sub
		notificationBindingSource.DataSource = DefaultDataSourceObject
	End Sub

	Protected Overrides Sub OnHandleDestroyed(ByVal e As System.EventArgs)
		dataSrc = Nothing
		MyBase.OnHandleDestroyed(e)
	End Sub

	Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
		MyBase.OnLoad(e)
		DefaultDataSourceObject = notificationBindingSource.DataSource
	End Sub
End Class
